package com.ifood.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ifood.common.core.domain.entity.SysCarouselInfo;
import com.ifood.system.service.ISysCarouselInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ifood.common.annotation.Log;
import com.ifood.common.core.controller.BaseController;
import com.ifood.common.core.domain.AjaxResult;
import com.ifood.common.enums.BusinessType;
import com.ifood.common.utils.poi.ExcelUtil;
import com.ifood.common.core.page.TableDataInfo;

/**
 * 录播图管理Controller
 *
 * @author ifood
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/system/carousel")
@Api(tags = "录播图管理")
public class SysCarouselInfoController extends BaseController {
    @Autowired
    private ISysCarouselInfoService sysCarouselInfoService;

    /**
     * 查询录播图管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询录播图管理列表")
    public TableDataInfo list(SysCarouselInfo sysCarouselInfo) {
        startPage();
        List<SysCarouselInfo> list = sysCarouselInfoService.selectSysCarouselInfoList(sysCarouselInfo);
        return getDataTable(list);
    }

    /**
     * 导出录播图管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "录播图管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCarouselInfo sysCarouselInfo) {
        List<SysCarouselInfo> list = sysCarouselInfoService.selectSysCarouselInfoList(sysCarouselInfo);
        ExcelUtil<SysCarouselInfo> util = new ExcelUtil<SysCarouselInfo>(SysCarouselInfo.class);
        util.exportExcel(response, list, "录播图管理数据");
    }

    /**
     * 获取录播图管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysCarouselInfoService.selectSysCarouselInfoById(id));
    }

    /**
     * 新增录播图管理
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "录播图管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCarouselInfo sysCarouselInfo) {
        return toAjax(sysCarouselInfoService.insertSysCarouselInfo(sysCarouselInfo));
    }

    /**
     * 修改录播图管理
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "录播图管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCarouselInfo sysCarouselInfo) {
        return toAjax(sysCarouselInfoService.updateSysCarouselInfo(sysCarouselInfo));
    }

    /**
     * 删除录播图管理
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "录播图管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysCarouselInfoService.deleteSysCarouselInfoByIds(ids));
    }
}
